using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Terra.Core.Common.Enums.Identity;
using Terra.Core.Common.Models.Pagination;

namespace Terra.Data.Models.Identity;


/// <summary>
/// 更新用户DTO
/// </summary>
public class UserBaseDto
{
    /// <summary>
    /// 用户ID
    /// </summary>
    public Guid Id { get; set; }

    /// <summary>
    /// 邮箱
    /// </summary>
    [EmailAddress]
    [MaxLength(256)]
    public string Email { get; set; }

    /// <summary>
    /// 手机号
    /// </summary>
    [MaxLength(32)]
    public string PhoneNumber { get; set; }

    /// <summary>
    /// 真实姓名
    /// </summary>
    [MaxLength(50)]
    public string RealName { get; set; }

    /// <summary>
    /// 昵称
    /// </summary>
    [MaxLength(50)]
    public string NickName { get; set; }

    /// <summary>
    /// 性别(0-未知，1-男，2-女)
    /// </summary>
    public int Gender { get; set; }

    /// <summary>
    /// 出生日期
    /// </summary>
    public DateTime? BirthDate { get; set; }

    /// <summary>
    /// 头像URL
    /// </summary>
    [MaxLength(1000)]
    public string AvatarUrl { get; set; }

    /// <summary>
    /// 个人简介
    /// </summary>
    [MaxLength(500)]
    public string Biography { get; set; }

    /// <summary>
    /// 用户类型
    /// </summary>
    public UserType UserType { get; set; }

    /// <summary>
    /// 用户状态
    /// </summary>
    public UserStatus Status { get; set; }

    

    /// <summary>
    /// 是否需要重置密码
    /// </summary>
    public bool RequiresPasswordReset { get; set; }
    /// <summary>
    /// 用户名
    /// </summary>
    public string UserName { get; set; }

    /// <summary>
    /// 邮箱是否已确认
    /// </summary>
    public bool EmailConfirmed { get; set; }

    /// <summary>
    /// 手机号是否已确认
    /// </summary>
    public bool PhoneNumberConfirmed { get; set; }

    /// <summary>
    /// 是否启用双因素认证
    /// </summary>
    public bool TwoFactorEnabled { get; set; }

    /// <summary>
    /// 账号锁定结束时间
    /// </summary>
    public DateTimeOffset? LockoutEnd { get; set; }

    /// <summary>
    /// 是否启用锁定
    /// </summary>
    public bool LockoutEnabled { get; set; }

    /// <summary>
    /// 访问失败次数
    /// </summary>
    public int AccessFailedCount { get; set; }

    /// <summary>
    /// 创建时间
    /// </summary>
    public DateTime CreatedTime { get; set; }

    /// <summary>
    /// 最后登录时间
    /// </summary>
    public DateTime? LastLoginTime { get; set; }

    /// <summary>
    /// 最后登录IP
    /// </summary>
    public string LastLoginIp { get; set; }

    /// <summary>
    /// 角色ID列表
    /// </summary>
    public List<Guid> RoleIds { get; set; }

    /// <summary>
    /// 角色列表
    /// </summary>
    public List<string> Roles { get; set; }
}

/// <summary>
/// 用户查询参数
/// </summary>
public class UserQueryDto : PagedRequest
{
    /// <summary>
    /// 用户名
    /// </summary>
    [MaxLength(256)]
    public string UserName { get; set; }

    /// <summary>
    /// 邮箱
    /// </summary>
    [MaxLength(256)]
    public string Email { get; set; }

    /// <summary>
    /// 手机号
    /// </summary>
    [MaxLength(32)]
    public string PhoneNumber { get; set; }

    /// <summary>
    /// 用户状态
    /// </summary>
    public UserStatus? Status { get; set; }

    /// <summary>
    /// 用户类型
    /// </summary>
    public UserType? UserType { get; set; }

    /// <summary>
    /// 注册开始时间
    /// </summary>
    public DateTime? StartTime { get; set; }

    /// <summary>
    /// 注册结束时间
    /// </summary>
    public DateTime? EndTime { get; set; }

    /// <summary>
    /// 角色ID
    /// </summary>
    public Guid? RoleId { get; set; }

    /// <summary>
    /// 关键字(用户名、邮箱、手机号、真实姓名、昵称)
    /// </summary>
    public new string Keyword { get; set; }
}

/// <summary>
/// 用户列表项DTO
/// </summary>
public class UserItemDto : UserBaseDto
{
    
}

/// <summary>
/// 用户详情DTO
/// </summary>
public class UserDetailDto : UserBaseDto
{

    /// <summary>
    /// 最后密码修改时间
    /// </summary>
    public DateTime? LastPasswordChangedTime { get; set; }
    
}

/// <summary>
/// 创建用户DTO
/// </summary>
public class UserCreateDto : UserBaseDto
{

    /// <summary>
    /// 密码
    /// </summary>
    [Required]
    [StringLength(100, MinimumLength = 6)]
    public string Password { get; set; }
    
}

/// <summary>
/// 更新用户DTO
/// </summary>
public class UserUpdateDto : UserBaseDto
{
    /// <summary>
    /// 用户ID
    /// </summary>
    [Required]
    public new Guid Id { get; set; }
}

/// <summary>
/// 重置密码DTO
/// </summary>
public class ResetPasswordDto
{
    /// <summary>
    /// 用户ID
    /// </summary>
    [Required]
    public Guid UserId { get; set; }

    /// <summary>
    /// 新密码
    /// </summary>
    [Required]
    [StringLength(100, MinimumLength = 6)]
    public string NewPassword { get; set; }

    /// <summary>
    /// 确认密码
    /// </summary>
    [Compare("NewPassword")]
    public string ConfirmPassword { get; set; }
}

/// <summary>
/// 更改密码DTO
/// </summary>
public class ChangePasswordDto
{
    /// <summary>
    /// 用户ID
    /// </summary>
    [Required]
    public Guid UserId { get; set; }

    /// <summary>
    /// 当前密码
    /// </summary>
    [Required]
    public string CurrentPassword { get; set; }

    /// <summary>
    /// 新密码
    /// </summary>
    [Required]
    [StringLength(100, MinimumLength = 6)]
    public string NewPassword { get; set; }

    /// <summary>
    /// 确认密码
    /// </summary>
    [Compare("NewPassword")]
    public string ConfirmPassword { get; set; }
}

/// <summary>
/// 用户状态更新DTO
/// </summary>
public class UserStatusUpdateDto
{
    /// <summary>
    /// 用户ID
    /// </summary>
    [Required]
    public Guid UserId { get; set; }

    /// <summary>
    /// 用户状态
    /// </summary>
    [Required]
    public UserStatus Status { get; set; }
}

/// <summary>
/// 角色分配DTO
/// </summary>
public class UserRoleAssignDto
{
    /// <summary>
    /// 用户ID
    /// </summary>
    [Required]
    public Guid UserId { get; set; }

    /// <summary>
    /// 角色ID列表
    /// </summary>
    [Required]
    public List<Guid> RoleIds { get; set; }
}